# LuckPay Web Manage System
#
# Copyright (c) 2016 Lucky Byte, Inc.
#
$ ->
    form = $('form.main')

    # 更新布局风格控件值
    layout = Cookies.get 'settings.layout_style'
    if layout then form.form 'set value', 'layout_style', layout

    # 更新语法着色值
    syntax = Cookies.get 'settings.syntax_style'
    if syntax then form.form 'set value', 'syntax_style', syntax

    # 更新表格活动唯一状态
    table_active_unique = Cookies.get 'settings.table_active_unique'
    if table_active_unique is 'on'
        form.find('.checkbox#table_active_unique').checkbox 'check'
    else
        form.find('.checkbox#table_active_unique').checkbox 'uncheck'

    # 保存设置按钮点击
    $('button#ok').click ->
        # 设置为繁忙状态
        $(this).addClass('loading disabled')

        # 修改页面布局风格
        layout = form.form 'get value', 'layout_style'
        Cookies.set 'settings.layout_style', layout, expires: 365, path: '/'

        # 修改语法着色风格
        syntax = form.form 'get value', 'syntax_style'
        Cookies.set 'settings.syntax_style', syntax, expires: 365, path: '/'

        # 表格活动唯一状态
        table_active_unique = form.form 'get value', 'table_active_unique'
        Cookies.set 'settings.table_active_unique', table_active_unique,
            expires: 365, path: '/'
